// Tabbed Pane project template
import bb.cascades 1.0
//import custom 1.0
import com.songs.data 1.0

TabbedPane {
    showTabsOnActionBar: true
    property variant selectedData;
    property bool activeContextMenu : false;
    Tab {
        title: qsTr("Nhạc Việt")
        imageSource: "asset:///images/listicon_v.png"
        SongsVNPage{
            id: songsVNPage
        }
        onTriggered:{
                songsENPage.txtSearch= "";
                songsVNPage.txtSearch= "";
                songsDataSource.query = "SELECT * FROM songs WHERE lang='v' ORDER BY title LIMIT 200";
                songsModel.clear();
                songsDataSource.load();
        } 
    }
    Tab {
            title: qsTr("Nhạc Anh")
            imageSource: "asset:///images/listicon_e.png"
            SongsENPage{
                id: songsENPage
            }
            
            onTriggered:{
                songsVNPage.txtSearch= "";
                songsENPage.txtSearch= "";
                songsDataSource.query = "SELECT * FROM songs WHERE lang='e' ORDER BY title LIMIT 200";
                songsModel.clear();
                songsDataSource.load();
                
            } 
    }
        
    Tab {
        title: qsTr("Yêu thích")
        imageSource: "asset:///images/favorite_70.png"
        SongsFavoritePage {
            id: songsFavPage
        }
        onTriggered:{
            songsDataSource.query = "SELECT * FROM songs WHERE is_favorite=1 ORDER BY title LIMIT 200";
            songsModel.clear();
            songsDataSource.load();
        } 
    }
    Tab {
        title: qsTr("Thông tin")
        imageSource: "asset:///images/abouticon.png"
        Page {
            id: tab3
            Container {
                // define tab content here
                topPadding: 50
                background: Color.create("#d9d9d9")
                ImageView {
                    horizontalAlignment: HorizontalAlignment.Center
                    imageSource: "asset:///images/logo-large.png"
                }
                Container {
                    layoutProperties: StackLayoutProperties {
                        spaceQuota: 1.0
                    }
                    verticalAlignment: VerticalAlignment.Fill
                    horizontalAlignment: HorizontalAlignment.Fill
                    Label {
                        text: qsTr ("Phiên bản 1.0.0 - Ariang Vol 47")
                        verticalAlignment: VerticalAlignment.Center
                        horizontalAlignment: HorizontalAlignment.Center
                        textStyle.color: Color.DarkBlue
                        textStyle {
                            base: SystemDefaults.TextStyles.BodyText
                        }
                    }
                    Label {
                        verticalAlignment: VerticalAlignment.Center
                        horizontalAlignment: HorizontalAlignment.Center
                        text: qsTr("Tác giả: it.tanloi@gmail.com")
                        textStyle.color: Color.create("#135a02")
                    }
                }
            }
        }
    }
    attachedObjects: [
        // See SongsModel.qml for set up of the GroupDataModel
        SongsModel {
            id: songsModel
            onUpdateSelectedData: {
                if (indexPath[0] >= 0 && indexPath[1] >= 0) {
                    //quotesList.scrollToItem(indexPath, ScrollAnimation.Default);
                    songs_vn.selectedData = data(indexPath);
                } else {
                    songs_vn.listEmpty();
                }
            }
        },
        // Custom data source object, loads data using a SqlConnection, see customsqldatasource.cpp
        //SongsVNSqlData{
        CustomSqlDataSource{
            id: songsDataSource
            source: "sql/songlist_v47.sqlite"
            query: "SELECT * FROM songs WHERE lang='v' ORDER BY title LIMIT 200"
            property int loadCounter: 0
            
            onDataLoaded: {
                if (data.length > 0){// && songsModel.childCount()==0) {
                    songsModel.insertList(data);
                    //execute("SELECT * FROM songs WHERE lang='v' ORDER BY title LIMIT 5 OFFSET "+ (10 + loadCounter*5),0)
                    //loadCounter++;

                }
            }
        }
    ] // attachedObjects
    onCreationCompleted: {
        // this slot is called when declarative scene is created
        // write post creation initialization here
        console.log("TabbedPane - onCreationCompleted()")

        // enable layout to adapt to the device rotation
        // don't forget to enable screen rotation in bar-bescriptor.xml (Application->Orientation->Auto-orient)
        OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
    }
    
}
